package com.nstar.base.util
{
	import flash.geom.ColorTransform;
	
	
	public class ColorUtils
	{
		
		public static var red:uint = 0xFF0000;
		public static var green:uint = 0x00FF00;
		public static var blue:uint = 0x0000FF;
		public static var yellow:uint = 0xFFFF00;
		
		public static function convertColor(color:String):Number{
			if(color.length > 1 && color.substring(0,1) == "#"){
				return Number("0x" + color.substring(1));
			}else{
				return Number(color);
			}
		}
		
		//颜色值转成16进制串
		public static function toHex(value:uint):String{
			var color:String = value.toString(16).toUpperCase();
			if(color.length>6)
				color = color.substr(color.length-6,6);
			return formatColor(color);
		}
		
		//混色，加两个颜色混合后产生的颜色
		public static function mixColor(color1:uint,color2:uint):uint{
			var r1:uint = (color1 & 0xFF0000)>>16;
			var g1:uint = (color1 & 0x00FF00)>>8;
			var b1:uint = color1 & 0x0000FF;
			var r2:uint = (color2 & 0xFF0000)>>16;
			var g2:uint = (color2 & 0x00FF00)>>8;
			var b2:uint = color2 & 0x0000FF;
			
//			三原色方式
//			var r:uint = (r1+r2)>255?255:(r1+r2);
//			var g:uint = (g1+g2)>255?255:(g1+g2);
//			var b:uint = (b1+b2)>255?255:(b1+b2);
						
			var r:uint = Math.round((r1+r2)/2);
			var g:uint = Math.round((g1+g2)/2);
			var b:uint = Math.round((b1+b2)/2);

			return (r<<16)+(g<<8)+b; 
			
		}

		
		//格式化颜色串，不足6位的在前面加0
		private static function formatColor(value:String):String{
			var len:int = value.length;
			var zeroStr:String = "";
			for(var i:int=0;i<6-len;i++){
				zeroStr +="0";
			}
			return zeroStr+value;
		}

	}
}